package fr.sharpe.app.earthvisualizationproject.tools;

import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;

public class ImageFactory {
	
	public static Image getImageFrom(String path)
	{
		Image image = null;
		System.out.println(path);
		if(path.contains("local:"))
		{
			String pathToFile = path.replaceFirst("local:", "");
			File file = new File(pathToFile);
		    try {
				image = ImageIO.read(file);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		else if (path.contains("http://"))
		{
			System.out.println("WEB IMAGE");
		    try {
		    	URL url = new URL(path);
				image = ImageIO.read(url);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		System.out.println(image);
		return image;
	}

}
